package view;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
import model.College;
import model.Reason;
import model.Teacher;

@SuppressWarnings("serial")
public class PanelAddAbsence extends JPanel {

	private static PanelAddAbsence single;
	ArrayList<Teacher> teacherList = new ArrayList<Teacher>(College
			.getInstance().getAllactiveTeachers());

	ArrayList<Reason> reasonList = new ArrayList<Reason>(College.getInstance()
			.getAllReasons());

	private JComboBox<String> uitvallerCombo;
	private JComboBox<String> invallerCombo;
	private JComboBox<String> redenCombo;
	private JComboBox<Integer> urencombo;

	private JButton add = new JButton("Opslaan");
	private JButton cancel = new JButton("Annuleren");

	private JLabel JLTeacher = new JLabel("Absente docent:");
	private JLabel JLSubstitute = new JLabel("Invaller:");
	private JLabel JLHours = new JLabel("Aantal uur:");
	private JLabel JLNote = new JLabel("Notities:");
	private JLabel JLStartDate = new JLabel("Begin datum:");
	private JLabel JLEndDate = new JLabel("Eind datum:");
	private JLabel JLReason = new JLabel("Reden:");
	private JLabel JTHours = new JLabel(
			" Uren worden uitgerekend adhv het rooster, en is nu standaard 1");
	private JTextField JTNote = new JTextField("");
	private JTextField JTReason = new JTextField("");
	private JSpinner JSStartDate = new JSpinner();
	private JSpinner JSEndDate = new JSpinner();
	
	public int previousPage;

	private PanelAddAbsence() {

		setLayout(null);
		setBounds(0, 0, 860, 720);

		add(PanelSelector.addTitle("Absentie toevoegen"));

		DefaultComboBoxModel<String> teacherCombo = new DefaultComboBoxModel<>();
		DefaultComboBoxModel<String> substituteCombo = new DefaultComboBoxModel<>();
		DefaultComboBoxModel<String> reasonCombo = new DefaultComboBoxModel<>();
		DefaultComboBoxModel<Integer> hoursCombo = new DefaultComboBoxModel<Integer>();
		for (int n = 0; n < teacherList.size(); n++) {
			teacherCombo.addElement(teacherList.get(n).getTeacher_code());

		}
		for (int n = 0; n < teacherList.size(); n++) {
			substituteCombo.addElement(teacherList.get(n).getTeacher_code());
			substituteCombo.setSelectedItem("GEEN");
		}

		redenCombo = new JComboBox<>(reasonCombo);
		uitvallerCombo = new JComboBox<>(teacherCombo);
		invallerCombo = new JComboBox<>(substituteCombo);

		urencombo = new JComboBox<>(hoursCombo);
		// redenenen voor afwezigheid

		redenCombo.addItem("Ziekte");
		redenCombo.addItem("Studie verlof");
		redenCombo.addItem("Algemeen verlof");
		redenCombo.addItem("Overig");

		// Maak een JSpinner aan met de huidige datum
		Date today = new Date();

		JSStartDate = new JSpinner(new SpinnerDateModel(today, null, null,
				Calendar.MONTH));
		JSpinner.DateEditor de = new JSpinner.DateEditor(JSStartDate,
				"dd/MM/yy");
		JSStartDate.setEditor(de);

		JSStartDate.setVisible(true);

		// Maak een JSpinner aan met de huidige datum
		JSEndDate = new JSpinner(new SpinnerDateModel(today, null, null,
				Calendar.MONTH));
		JSpinner.DateEditor de1 = new JSpinner.DateEditor(JSEndDate, "dd/MM/yy");
		JSEndDate.setEditor(de1);
		JSEndDate.setVisible(true);

		urencombo.setBounds(400, 230, 250, 30);
		uitvallerCombo.setBounds(400, 150, 140, 30);
		invallerCombo.setBounds(400, 190, 140, 30);
		// http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html
		JTHours.setBounds(400, 230, 500, 30);
		redenCombo.setBounds(400, 270, 140, 30);
		JTNote.setBounds(400, 310, 250, 30);
		JSStartDate.setBounds(400, 350, 140, 30);
		JSEndDate.setBounds(400, 400, 140, 30);

		JLTeacher.setBounds(260, 150, 140, 30);
		JLSubstitute.setBounds(260, 190, 140, 30);
		JLHours.setBounds(260, 230, 140, 30);
		JLReason.setBounds(260, 270, 140, 30);
		JLNote.setBounds(260, 310, 140, 30);
		JLStartDate.setBounds(260, 350, 140, 30);
		JLEndDate.setBounds(260, 390, 140, 30);

		add.setBounds(400, 500, 140, 30);
		cancel.setBounds(500, 500, 140, 30);

		add.addActionListener(new controller.AddAbsence(this));

		add(uitvallerCombo);
		add(invallerCombo);
		add(JTHours);
		add(JSStartDate);
		add(JSEndDate);
		add(JTNote);
		add(redenCombo);
		add(JLTeacher);
		add(JLSubstitute);
		add(JLHours);
		add(JLStartDate);
		add(JLEndDate);
		add(JLNote);
		add(JLReason);
		add(add);

	}

	public static PanelAddAbsence getInstance() {
		if (single == null) {
			single = new PanelAddAbsence();
		}
		return single;
	}

	public void selfDestroy() {
		single = null;
	}

	public static PanelAddAbsence getSingle() {
		return single;
	}

	public static void setSingle(PanelAddAbsence single) {
		PanelAddAbsence.single = single;
	}

	public JButton getAdd() {
		return add;
	}

	public void setAdd(JButton add) {
		this.add = add;
	}

	public JButton getCancel() {
		return cancel;
	}

	public void setCancel(JButton cancel) {
		this.cancel = cancel;
	}

	public JComboBox<String> getUitvallerCombo() {
		return uitvallerCombo;
	}

	public void setUitvallerCombo(JComboBox<String> uitvallerCombo) {
		this.uitvallerCombo = uitvallerCombo;
	}

	public JComboBox<String> getInvallerCombo() {
		return invallerCombo;
	}

	public void setInvallerCombo(JComboBox<String> invallerCombo) {
		this.invallerCombo = invallerCombo;
	}

	public ArrayList<Teacher> getTeacherList() {
		return teacherList;
	}

	public void setTeacherList(ArrayList<Teacher> teacherList) {
		this.teacherList = teacherList;
	}

	public JLabel getJLTeacher() {
		return JLTeacher;
	}

	public void setJLTeacher(JLabel jLTeacher) {
		JLTeacher = jLTeacher;
	}

	public JLabel getJLSubstitute() {
		return JLSubstitute;
	}

	public void setJLSubstitute(JLabel jLSubstitute) {
		JLSubstitute = jLSubstitute;
	}

	public JLabel getJLHours() {
		return JLHours;
	}

	public void setJLHours(JLabel jLHours) {
		JLHours = jLHours;
	}

	public JLabel getJLNote() {
		return JLNote;
	}

	public void setJLNote(JLabel jLNote) {
		JLNote = jLNote;
	}

	public JLabel getJLReason() {
		return JLReason;
	}

	public void setJLReason(JLabel jLReason) {
		JLReason = jLReason;
	}

	// public JLabel getJLHours2() {
	// return JLHours2;
	// }
	//
	// public void setJTHours(JLabel JLHours2) {
	// JLHours2 = this.JLHours2;
	// }

	public JTextField getJTNote() {
		return JTNote;
	}

	public void setJTNote(JTextField jTNote) {
		JTNote = jTNote;
	}

	public JTextField getJTReason() {
		return JTReason;
	}

	public int getpreviousPage() {
		return previousPage;
	}

	public void setpreviousPage(int previousPage) {
		this.previousPage = previousPage;
	}

	public void setJTReason(JTextField jTReason) {
		JTReason = jTReason;
	}

	public JComboBox<String> getRedenCombo() {
		return redenCombo;
	}

	public void setRedenCombo(JComboBox<String> redenCombo) {
		this.redenCombo = redenCombo;
	}

	public JLabel getJLStartDate() {
		return JLStartDate;
	}

	public void setJLStartDate(JLabel jLStartDate) {
		JLStartDate = jLStartDate;
	}

	public JLabel getJLEndDate() {
		return JLEndDate;
	}

	public void setJLEndDate(JLabel jLEndDate) {
		JLEndDate = jLEndDate;
	}

	public JSpinner getJSStartDate() {
		return JSStartDate;
	}

	public void setJSStartDate(JSpinner jSStartDate) {
		JSStartDate = jSStartDate;
	}

	public JSpinner getJSEndDate() {
		return JSEndDate;
	}

	public void setJSEndDate(JSpinner jSEndDate) {
		JSEndDate = jSEndDate;
	}

	public ArrayList<Reason> getReasonList() {
		return reasonList;
	}

	public void setReasonList(ArrayList<Reason> reasonList) {
		this.reasonList = reasonList;
	}

}
